(function() {
	require(['jquery', 'select2'], function(jquery,vbox) {
		
		if(typeof jQuery === 'undefined') {	//检测jquery依赖项
			throw new Error('jquery依赖项未能加载');
		}
		
		if(typeof $.fn.bootstrapValidator === 'undefined') {	//检测bootstrapValidator依赖项
			throw new Error('bootstrapValidator依赖项未能加载');
		}
	
		/*工程名称下拉列表*/
		$.ajax({
			url: 'projectCotegory/retieveProjectCotegorys.service',
			type: 'post',
			success: function(data) {
				var _data = data.data;
				var select2Data = $.map(_data, function (obj) {
					obj.text = obj.name; 
					obj.id = obj.id;
					return obj;
				});
				$("#update_project").select2({
					placeholder: "工程名称",
					allowClear: true,
					data: select2Data,
					minimumResultsForSearch: Infinity
				});
			}
		});
		
		$.ajax({
			url: 'targetAttribute/retrieveTargetAttributes.service',
			type: 'post',
			success: function(data) {
				var _data = data.data;
				var select2Data = $.map(_data, function (obj) {
					obj.text = obj.text || obj.targetAttribute;
					obj.id = obj.id;
					return obj;
				});
				$("#update_attribute").select2({
					placeholder: "项目名称",
					allowClear: true,
					data: select2Data,
					minimumResultsForSearch: Infinity
				});
			}
		});
	
		$('#update_project').change(function() {
			var pcid = $("#update_project").val();
			项目名称下拉列表
			$.ajax({
				url: 'targetAttribute/retrieveTargetAttributeBypcid.service',
				type: 'post',
				data: {
					pcid: pcid
				},
				success: function(data) {
					var _data = data.data;
					var select2Data = $.map(_data, function (obj) {
						  obj.text = obj.text || obj.targetAttribute; 
						  obj.id = obj.id;
						  return obj;
						});
					$("#update_attribute").empty();
					$("#update_attribute").select2({
						 placeholder: "项目名称",
						 allowClear: true,
						 data: select2Data,
						 minimumResultsForSearch: Infinity
					 });
				}
			});
		});
		
	});
})();